xfluxcali ( )
{

        echo "========xfluxcali========="
gnuplot << EOF
set term png
set output "aa.png"
set xlabel "gft mag"
set ylabel "PS1 mag"
set grid
set key left
f(x)=a*x+b
a=1
fit f(x) 'matched.txt' u 9:10 via b  
plot 'matched.txt' u 9:10 t 'mag-mag',f(x)
quit
EOF

#in the gnuplot, a=1 is aiming to make the correct fit .
#cp fit.log fit.log.bak
#when fit above with only b
aa=1
bb=`cat fit.log | tail -7 | head -1 | awk '{print($3)}'`

#when fit above, via a,b,  the values of aa and bb are in the following
#aa=`cat fit.log | tail -9 | head -1 | awk '{print($3)}'`
#bb=`cat fit.log | tail -8 | head -1 | awk '{print($3)}'`
echo "the transformation format is f(x)="$aa"*x+"$bb
meandelmag=`echo $bb | awk '{print($1)}'`

}

xfluxcali
